package com.flying.admin.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.annotation.Transaction;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.data.Data;
import com.flying.framework.service.AbstractService;

@Service(value="ServiceEvent", desc="事件记录")
public class ServiceEvent extends AbstractService{
	public final static String TABLE_NAME = "sys_service_event";
	private ServiceEventDetail sed;
	
	public void setEventDetail(ServiceEventDetail d) {
		this.sed = d;
	}
	
	public enum Field {
		
		event_id       ("event_id",          "int",	"日志ID"),
		event_date     ("event_date",        "Date",	"服务时间"),
		app_id         ("app_id",            "String",	"应用ID"),
		module_id      ("module_id",         "String",	"模块ID"),
		service_id     ("service_id",        "String",	"服务ID"),
		service_method ("service_method",    "String",	"服务接口"),
		principle      ("principle",         "String",	"服务用户"),
		tid            ("tid",               "int",	"交易ID"),
		consume        ("consume",           "int",	"消耗时长(ms)"),
		return_code    ("return_code",       "String",	"返回码");
		
		public final String fieldName;
		public final String fieldType;
		public final String fieldComment;
	
		Field(String name, String dataType, String comment) {
			this.fieldName 		= name;
			this.fieldType		= dataType;
			this.fieldComment	= comment;
		}
	}
    
	@MethodInfo("创建事件记录")
	@Transaction
	public Data create(
		
			@Param(value="event_date",        required=false,	desc="服务时间") Date event_date,
			@Param(value="app_id",            required=false,	desc="应用ID") String app_id,
			@Param(value="module_id",         required=false,	desc="模块ID") String module_id,
			@Param(value="service_id",        required=false,	desc="服务ID") String service_id,
			@Param(value="service_method",    required=false,	desc="服务接口") String service_method,
			@Param(value="principle",         required=false,	desc="服务用户") String principle,
			@Param(value="tid",               required=false,	desc="交易ID") long tid,
			@Param(value="consume",           required=false,	desc="消耗时长") int consume,
			@Param(value="return_code",       required=false,	desc="返回码") String return_code,

			@Param(value="input",             required=false,	desc="输入") String input,
			@Param(value="output",            required=false,	desc="输出") String output,
			@Param(value="error",             required=false,	desc="错误") String error
		
		) throws Exception {
		
		Data event = this.daoCreate(event_date, app_id, module_id, service_id, service_method, principle, tid, consume, return_code);
		long event_id = event.getLong(Field.event_id.fieldName, 0L);
		this.sed.create(event_id, input, output, error);
		
		return event;
	}
        
	@MethodInfo("创建事件记录")
	@DaoCreate(entity="sys_service_event")
	protected Data daoCreate(
		
			@Param(value="event_date",        required=false,	desc="服务时间") Date event_date,
			@Param(value="app_id",            required=false,	desc="应用ID") String app_id,
			@Param(value="module_id",         required=false,	desc="模块ID") String module_id,
			@Param(value="service_id",        required=false,	desc="服务ID") String service_id,
			@Param(value="service_method",    required=false,	desc="服务接口") String service_method,
			@Param(value="principle",         required=false,	desc="服务用户") String principle,
			@Param(value="tid",               required=false,	desc="交易ID") long tid,
			@Param(value="consume",           required=false,	desc="消耗时长") int consume,
			@Param(value="return_code",       required=false,	desc="返回码") String return_code
		
		) throws Exception {
		
		return null;
	}

	@MethodInfo("修改事件记录")
	@DaoUpdate(entity="sys_service_event")
	public Data update(
		
			@Param(value="event_id",          required=false,	desc="日志ID") long event_id,
			@Param(value="event_date",        required=false,	desc="服务时间") Date event_date,
			@Param(value="app_id",            required=false,	desc="应用ID") String app_id,
			@Param(value="module_id",         required=false,	desc="模块ID") String module_id,
			@Param(value="service_id",        required=false,	desc="服务ID") String service_id,
			@Param(value="service_method",    required=false,	desc="服务接口") String service_method,
			@Param(value="principle",         required=false,	desc="服务用户") String principle,
			@Param(value="tid",               required=false,	desc="交易ID") long tid,
			@Param(value="consume",           required=false,	desc="消耗时长") int consume,
			@Param(value="return_code",       required=false,	desc="返回码") String return_code,
			@Param(value="fields", required=false, desc="更新字段", tag="fields") String[] fields
			
		) throws Exception {
		
		return null;
	}

	@MethodInfo("删除事件记录")
	@DaoRemove(entity="sys_service_event")
	public Data remove(
		
			@Param(value="event_id",          required=true,	desc="日志ID") long event_id
		
		) throws Exception {
		
		return null;
	}

	@MethodInfo("查询所有事件记录")
	@DaoQuery(entity="sys_service_event")
	public Data findAll() throws Exception {
		return null;
	}

	@MethodInfo("根据主键查询事件记录")
	@DaoQuery(entity="sys_service_event", single=true)
	public Data findById(
		
			@Param(value="event_id",          required=true,	desc="日志ID") long event_id
		
		) throws Exception {
		return null;
	}

}